      SUBROUTINE TRKNT(Y1,Y1P,Y2,Y2P,X,Y)
c
c23456789012345678901234567890123456789012345678901234567890123456789012
c
C*** TOROIDAL AND RADIAL MODE COUNTER ***
c
c    calls no other routines
c
      IMPLICIT REAL*8(A-H,O-Z)
c
      SAVE
      COMMON/BITS/PI,RN,VN,WN,W,WSQ,WRAY,QINV,CG,WGRAV,TREF,FCT,EPS,FL,
     +  FL1,FL2,FL3,SFL3,JCOM,NORD,L,KG,KOUNT,KNSW,IFANIS,IBACK
      DIMENSION XS(2),VAL(4)
      DATA XS/2*0.D0/,VAL/4*0.D0/
c
      NS=0
      IF(KOUNT.EQ.0) GOTO 60
      H=Y-X
      A1=H*Y1P
      A2=-H*(2.D0*Y1P+Y2P)+3.D0*(Y2-Y1)
      A3=H*(Y1P+Y2P)-2.D0*(Y2-Y1)
      A33=3.D0*A3
      A22=2.D0*A2
      IF(A3.NE.0.D0) GOTO 20
      IF(A2.EQ.0.D0) GOTO 50
      XS(1)=-A1/A22
      IF(XS(1).GE.0.D0.AND.XS(1).LE.1.D0) NS=1
      GOTO 50
   20 DISC=A2*A2-A1*A33
      IF(DISC) 50,25,30
   25 XS(1)=-A2/A33
      IF(XS(1).GE.0.D0.AND.XS(1).LE.1.D0) NS=1
      GOTO 50
   30 DISC=DSQRT(DISC)
      TR1=(-A2+DISC)/A33
      TR2=(-A2-DISC)/A33
      IF(DABS(A33).GT.DABS(A1)) GOTO 35
      FAC=A1/A33
      TR1=FAC/TR1
      TR2=FAC/TR2
   35 IF(TR1.LT.0.D0.OR.TR1.GT.1.D0) GOTO 40
      XS(1)=TR1
      NS=1
   40 IF(TR2.LT.0.D0.OR.TR2.GT.1.D0) GOTO 50
      NS=NS+1
      XS(NS)=TR2
      IF(NS.LT.2) GOTO 50
      IF(TR2.GE.TR1) GOTO 50
      XS(1)=TR2
      XS(2)=TR1
   50 IF(NS.EQ.0) GOTO 60
      NS1=NS+1
      DO 55 J=2,NS1
      T=XS(J-1)
   55 VAL(J)=Y1+T*(A1+T*(A2+T*A3))
   60 VAL(1)=Y1
      NS2=NS+2
      VAL(NS2)=Y2
      DO 100 J=2,NS2
  100 IF(VAL(J-1)*VAL(J).LE.0.D0) KOUNT=KOUNT+1
      IF(VAL(1).EQ.0.D0) KOUNT=KOUNT-1
c
      RETURN
      END
